import { ADD_LIST , INPUT_VALUE , DEL_ITEM ,GET_lIST} from "./actionType";

const defaultState = {
    list:[],
    inputValue:''
}

const reducer = (state = defaultState,action)=>{
    if(action.type == ADD_LIST){
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.push(newState.inputValue)
        return newState
    }
    if(action.type == INPUT_VALUE){
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputValue = action.value
        return newState
    }
    if(action.type == DEL_ITEM){
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.splice(action.index,1)
        return newState
    }

    if(action.type == GET_lIST){
        let newState = JSON.parse(JSON.stringify(state))
        newState.list =action.data
        return newState
    }
    return state
}

export default reducer;